package yxy.game.pm2.module.therionHunting;

import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import yxy.apple.util.ActiveUtil;
import yxy.game.pm2.bean.area.AreaGroupBean;
import yxy.game.pm2.bean.timeline.FutureRunnable;

import java.util.Collection;

/**
 * @author wrs
 * @name TherionFuture
 * @description 跨服神兽玩法定时器 定时刷新
 * @since 2022-06-09
 */
public class TherionAreaGroupBeanFuture extends FutureRunnable {

    @Override
    public long period() {
        return DateTimeConstants.MILLIS_PER_MINUTE * 5;// 5分钟一刷
    }

    @Override
    public void init() {
        handle();
    }

    @Override
    public void tick() {
        handle();
    }


    private void handle() {

        DateTime now = DateTime.now();
        DateTime dateTime = ActiveUtil.time2(now);
        //2.前不执行逻辑
        if(now.isBefore(dateTime))return;

        TherionFutureHandle therionFutureHandle = new TherionFutureHandle();
        //跨服
        Collection<AreaGroupBean> areaGroupBeans = AreaGroupBean.all();
        for (AreaGroupBean areaGroupBean : areaGroupBeans) {
            try {
                therionFutureHandle.areaGroupBeanUpdate(areaGroupBean);//跨服刷新
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }



}
